package jjn.round2;

/**
 * @author Jiang Jining
 * @since 2023-05-05 18:40
 */
public class LeetCode2432_HardestWorker {
    public int hardestWorker(int n, int[][] logs) {
        int length = logs.length;
        int longest = 0, worker = 0, last = 0;
        for (int i = 0; i < length; i++) {
            int[] log = logs[i];
            int id = log[0];
            if (i == 0) {
                worker = id;
                longest = log[1];
            } else {
                int duration = log[1] - last;
                if (duration > longest) {
                    worker = id;
                    longest = duration;
                }
                if (duration == longest) {
                    worker = Math.min(worker, id);
                }
            }
            last = log[1];
        }
        return worker;
    }
}
